<template>
  <div class="selection-wrap">
      <div class="selection-show" @click="toogleDrop">
        <span>{{ selections[nowIndex].label }}</span>
        <div class="arrow" ></div>
      </div>
      <div class="selection-list" v-if="dropFlag">
          <ul>
              <li v-for="(item,index) in selections" @click="selectOne(index)">{{ item.label }}</li>
          </ul>
      </div>
  </div>
</template>

<script>
export default {
  props:{
      selections:{
          type: Array,
          default: {
              label: '无选项',
              value: 0
          }
      }
  },
  data () {
      return {
          nowIndex: 0,
          dropFlag: false
      }
  },
  methods:{
      toogleDrop () {
          this.dropFlag = !this.dropFlag
      },
      selectOne (index) {
          this.nowIndex = index
          this.dropFlag = false
          this.$emit('on-change',index)
      }
  }
}
</script>

<style scoped>
.selection-wrap{
    position: relative;
    display: inline-block;
}

.selection-show{
    position: relative;    
    display: inline-block;
    padding: 0 20px 0 10px;
    border: 1px solid #e3e3e3;
    cursor: pointer;
    height: 25px;
    line-height: 25px;
    border-radius: 3px;
    background: #fff;
}

.selection-show .arrow{
    display: inline-block;
    width: 0;
    height: 0;
    border: 5px transparent solid;
    border-top: 5px #e3e3e3 solid;
    margin: -1px -14px 0 6px;
    vertical-align: middle;
}

.selection-drap{
    position: absolute;
}

.selection-list {
  display: inline-block;
  position: absolute;
  left: 0;
  top: 25px;
  width: 100%;
  background: #fff;
  border-top: 1px solid #e3e3e3;
  border-bottom: 1px solid #e3e3e3;
  z-index: 5;
}

.selection-list li {
  padding: 5px 15px 5px 10px;
  border-left: 1px solid #e3e3e3;
  border-right: 1px solid #e3e3e3;
  cursor: pointer;
  background: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

}
.selection-list li:hover {
  background: #e3e3e3;
}

</style>
